import INavigate from "../../Interfaces/INavigate";
import Oriented from "../../Constants/Oriented";
import G from "../../Utilities/Global";

/**
 * 垂直寻路
 * created by Five on 2018-12-24 11:01:01
 */

export default class PatrolVert implements INavigate {
    oriented: any; speed: number;

    // 默认方向 左上右下
    setdir(dir: Oriented) {
        if (dir == Oriented.LEFT)
            this.oriented = Oriented.UP;
        else
            this.oriented = Oriented.DOWN;
    }

    setspeed(sp: number) {
        this.speed = sp;
    }

    setsize(s: number) {
    }

    settarget(node: cc.Node) {
    }

    update(dt: number, node: cc.Node, aniNode: cc.Node) {
        let speed = this.oriented == Oriented.UP ? this.speed : this.speed * -1;
        let target = node.position.add(cc.v2(0, speed * dt));
        let upordown = G().Calc.UD(target, this.oriented);
        let entityTar = G().CurScene.MapData.GetWallByPosition(upordown);
        if (!entityTar) {
            node.position = target;
        } else {
            this.oriented = this.oriented == Oriented.UP ? Oriented.DOWN : Oriented.UP;
            G().CurScene.BoomTile(upordown, true);
        }
    }
}